package com.pi.pro.xcmg.am.was.edi.wcs.service;





import com.pi.common.utils.TextUtils;
import com.pi.core.exchange.vo.NamedServiceProxy;
import com.pi.pro.xcmg.am.common.XcmgAmConstants;
import com.pi.pro.xcmg.am.was.edi.wcs.common.WcsWasExchangeSupport;
import com.pi.pro.xcmg.am.was.edi.wcs.dto.CommonResultData;
import com.pi.pro.xcmg.am.was.edi.wcs.dto.TransportTaskData;
import com.pi.wms.fac.conn.HttpAccessUrl;
import com.pi.wms.fac.conn.HttpConstants;
import com.pi.wms.fac.conn.HttpclientProxy;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;



/**
 */
@Getter
@Setter
public class TasklistServiceProxy implements NamedServiceProxy {

    private String category;
    private String code;

    private HttpclientProxy wcsTaskClient;
    private HttpAccessUrl wcsTaskExecutePostAccessUrl;

    //
    public CommonResultData execute(List<TransportTaskData> tasks) {
        CommonResultData replyData=null;
        String replyText = "";
        if (this.wcsTaskClient==null){
            return WcsWasExchangeSupport.error("install client error");
        }
        Map<String,String> headers = new HashMap<>();
        try{
            //headers.put("Content-Type", XcmgAmConstants.HTTP_CONTENT_TYPE_HTTP_JSON);

            replyText = this.wcsTaskClient.post(this.wcsTaskExecutePostAccessUrl, null, headers,
                    HttpConstants.URL_METHOD_POST, TextUtils.toListJsonText(tasks));
            replyData= TextUtils.toObject(replyText, CommonResultData.class);
        }catch (Exception e){
            e.printStackTrace();
            replyText="send task report error.//"+e.getMessage();
            replyData= WcsWasExchangeSupport.error(replyText);
        }
        return replyData;
    }
}
